package com.linkhub.oms.admin.modules.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.admin.modules.user.domain.param.MerchantBankCardModifyParam;
import com.linkhub.oms.admin.modules.user.domain.param.MerchantCompanyModifyParam;
import com.linkhub.oms.admin.modules.user.domain.param.MerchantCompanyModifyParamV2;
import com.linkhub.oms.admin.modules.user.domain.vo.MerchantPersonalInfoVO;
import com.linkhub.oms.admin.modules.user.service.UserBizService;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description: MerchantPersonalInfoController
 * @Author: echo
 * @Date: 2024/5/16 20:29
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = {"商家个人信息模块"})
@RequestMapping("/merchant")
@SaCheckLogin
@SaCheckRole(value = RoleConstant.CUSTOMER)
public class MerchantPersonalInfoController {

    @Resource
    private UserBizService userBizService;


    @GetMapping("/personal/info")
    @ApiOperation(value = "查询商家个人信息接口")
    public DataResponse<MerchantPersonalInfoVO> getUserPersonalInformation() {

        return DataResponse.success(userBizService.getUserPersonalInformation(LhSessionContext.getUserId()));
    }

    @PostMapping("/company")
    @ApiOperation(value = "新增or编辑公司信息")
    public DataResponse<Void> modifyCompanies(@Valid @RequestBody MerchantCompanyModifyParam companyModifyParam) {
        userBizService.modifyCompany(companyModifyParam);
        return DataResponse.success();
    }

    @PostMapping("/company/v2")
    @SaIgnore
    @ApiOperation(value = "新增or编辑公司信息V2（暂未有编辑逻辑）")
    public DataResponse<Void> modifyCompanyV2(@Valid @RequestBody MerchantCompanyModifyParamV2 merchantCompanyModifyParamV2) {
        userBizService.modifyCompanyV2(merchantCompanyModifyParamV2);
        return DataResponse.success();
    }

    @PostMapping("/bank/card")
    @ApiOperation(value = "新增or编辑银行卡")
    public DataResponse<Void> modifyBankCards(@Valid @RequestBody MerchantBankCardModifyParam bankCardModifyParam) {
        userBizService.modifyBankCard(bankCardModifyParam);
        return DataResponse.success();
    }

    @DeleteMapping("/company/{id}")
    @ApiOperation(value = "删除公司信息")
    public DataResponse<Void> deleteCompany(@PathVariable("id") Long id) {
        userBizService.deleteCompany(id);
        return DataResponse.success();
    }

    @DeleteMapping("/bank/card/{id}")
    @ApiOperation(value = "删除银行卡")
    public DataResponse<Void> deleteBankCard(@PathVariable("id") Long id) {
        userBizService.deleteBankCard(id);
        return DataResponse.success();
    }

}
